#include <iostream>
using namespace std;

//船体
class ShipBody{
public:
    virtual string getBody() = 0;
    virtual ~ShipBody() {}

};
//木头船体
class WoodBody : public ShipBody{
public:
    string getBody() override{
        return string("木头船体...");
    }

};
//钢铁船体
class IronBody : public ShipBody{
public:
    string getBody() override{
        return string("钢铁船体...");
    }

};
//合成金属船体
class MetalBody : public ShipBody{
public:
    string getBody() override{
        return string("合成金属船体...");
    }

};
//引擎
class Engine{
public:
    virtual string getEngine() = 0;
    virtual ~Engine() {}
};
//人工引擎
class HumanEngine : public Engine{
public:
    string getEngine() override{
        return string("人工引擎...");
    }
};
//内燃机引擎
class DieselEngine : public Engine{
public:
    string getEngine() override{
        return string("内燃机引擎...");
    }
};
//核动力引擎
class NuclearEngine : public Engine{
public:
    string getEngine() override{
        return string("核动力引擎...");
    }
};
//武器
class Weapon{
public:
    virtual string getWeapon() = 0;
    virtual ~Weapon() {}
};
//枪
class GunWeapon : public Weapon{
public:
    string getWeapon() override{
        return string("武器--枪...");
    }
};
//加农泡
class CannonWeapon : public Weapon{
public:
    string getWeapon() override{
        return string("武器--加农泡...");
    }
};
//激光
class LaserWeapon : public Weapon{
public:
    string getWeapon() override{
        return string("武器--激光...");
    }
};

//船
class Ship{
public:
    Ship(ShipBody* body, Engine* engine, Weapon* weapon):
        m_body(body), m_engine(engine), m_weapon(weapon){}
    ~Ship(){
        delete m_body;
        delete m_engine;
        delete m_weapon;
    }
    string getProperty(){
        string info = m_body->getBody() + m_weapon->getWeapon() + m_engine->getEngine();
        return info;
    }
private:
    ShipBody* m_body;
    Engine* m_engine;
    Weapon* m_weapon;

};

//工厂类 - 抽象
class AbstractFactory{
public:
    virtual Ship* createShip() = 0;
    virtual ~AbstractFactory() {}
};
//生产基础船
class BasicFactory : public AbstractFactory{
public:
    Ship* createShip() override{
        Ship* ship = new Ship(new WoodBody, new HumanEngine, new GunWeapon);
        cout << "基础船--木头船体--人力--枪" << endl;
        return ship;
    }
};
//生产标准船
class StandardFactory : public AbstractFactory{
public:
    Ship* createShip() override{
        Ship* ship = new Ship(new IronBody, new DieselEngine, new CannonWeapon);
        cout << "标准船--钢铁船体--内燃机--加农炮" << endl;
        return ship;
    }
};
//生产基础船
class UltimateFactory : public AbstractFactory{
public:
    Ship* createShip() override{
        Ship* ship = new Ship(new MetalBody, new NuclearEngine, new LaserWeapon);
        cout << "旗舰船--合成金属船体--核动力--激光" << endl;
        return ship;
    }
};

int main(){
    //下单旗舰船
    AbstractFactory* factory = new UltimateFactory;
    Ship* ship = factory->createShip();
    cout << ship->getProperty() << endl;
    delete ship;
    delete factory;
    return 0;
}